package com.nny.Demo603;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao {
    private static DbUntil dbUntil = new DbUntil();
    Connection  conn = dbUntil.getCon();
    public UserDao() throws  ClassNotFoundException, SQLException {
    }
    public User findUser(String username,String password) throws SQLException {
        String sql = "select * from user where username = ? and password = ?";
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
         preparedStatement.setString(1,username);
          preparedStatement.setString(2,password);
          ResultSet resultSet = preparedStatement.executeQuery();
          User user = new User();
           if(resultSet.next()){
               int id  = resultSet.getInt("id");
               String name = resultSet.getString("username");
                String pwd = resultSet.getString("password");
                  user = new User(id,username,password);
               User User = new User(id, username, password);
               User.setId( id);
                User.setUsername(name);
                User.setPassword(pwd);
          }

            return user;
        }

}
